package org.come.until;

import com.tool.btn.LotteryNineBtn;
import com.tool.image.ImageMixDeal;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
import com.updateNew.MyIsif;
import org.apache.commons.lang.StringUtils;
import org.come.entity.Goodstable;
import org.come.entity.LotteryGood;
import org.come.mouslisten.*;

import javax.swing.*;
import java.awt.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;

public class LotteryFromServerUntil {//修改物品栏物品显示
    private static List<LotteryGood> Goodslist = new ArrayList<LotteryGood>();
    private static List<LotteryGood> showlist = new ArrayList<LotteryGood>();
    //private static ImageIcon[] goodimg = new ImageIcon[9];// 存放当前背包页面的img
    private static int record = 0;
    private static Image image= CutButtonImage.getImage("img/item/FFBG00.png", -1, -1).getImage();

    private static Image bgimage1= CutButtonImage.getImage("img/item/FFBG01.png", -1, -1).getImage();
    private static Image bgimage2= CutButtonImage.getImage("img/item/FFBG02.png", -1, -1).getImage();
    private static Image bgimage3= CutButtonImage.getImage("img/item/FFBG03.png", -1, -1).getImage();
    private static Image bgimage4= CutButtonImage.getImage("img/item/FFBG04.png", -1, -1).getImage();
    private static boolean hasStart = false;

    public static boolean isHasStart() {
        return hasStart;
    }

    public static void setHasStart(boolean hasStart) {
        LotteryFromServerUntil.hasStart = hasStart;
    }

    public static int getRecord() {
        return record;
    }

    public static int upRecord() {
        return record += 1;
    }

    public static void setRecord(int record) {
        LotteryFromServerUntil.record = record;
    }
    public static Sprite path = SpriteFactory.VloadSprite("resource/mouse/xipai.tcp", null);
    public static Sprite tcp = SpriteFactory.VloadSprite("resource/mouse/zhuan.tcp", null);
    public static Sprite tcp1 = SpriteFactory.VloadSprite("resource/mouse/FFLFY.tcp", null);
    public static Map<BigDecimal, Goodstable> chatGoods = new HashMap<BigDecimal, Goodstable>();

    public static void draw(Graphics g, int x, int y) {
        if (MyIsif.getStyle().equals("水墨UI")) {
            int i = 0;
            if (LotteryNineBtn.isXIPAI) {

                path.updateToTime(ImageMixDeal.userimg.getTime(), 1);
                path.draw(g, x, y);

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(1000);
                            LotteryNineBtn.isXIPAI = false;
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }else {
                while (i < 9) {
                    final int row = i % 3 * 72;
                    final int col = i / 3 * 72;
                    if (LotteryFromServerUntil.Goodslist != null && LotteryFromServerUntil.Goodslist.size() >= 9) {
                        if (LotteryFromServerUntil.Goodslist.get(i).getLotterystep() == 1) {
                            g.drawImage(image, x - 6 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                        } else {
                            if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG01")) {
                                g.drawImage(bgimage1, x - 6 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                            } else if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG02")) {
                                g.drawImage(bgimage2, x - 6 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                            } else if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG03")) {
                                g.drawImage(bgimage3, x - 6 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                            } else if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG04")) {
                                g.drawImage(bgimage4, x - 6 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                                tcp.updateToTime(ImageMixDeal.userimg.getTime(), 4);
                                tcp.draw(g, x - 6 + row + 1, y - 2 + col + 1 + 3);
                            }

                            g.drawImage(CutButtonImage.getImage("img/item/" + LotteryFromServerUntil.Goodslist.get(i).getSkin() + ".png", -1, -1).getImage(), x +2 + row + 2 + 1, y + col + 1 + 9, 53, 53, null);
                        }
                    }
                    ++i;
                }
                LotteryNineBtn.isXIPAI = false;
            }
        } else {
            int i = 0;
            if (LotteryNineBtn.isXIPAI) {
                while (i < 9) {
                    final int row = i % 3 * 72;
                    final int col = i / 3 * 72;
                    if (LotteryFromServerUntil.Goodslist != null && LotteryFromServerUntil.Goodslist.size() >= 9) {
                        path.updateToTime(ImageMixDeal.userimg.getTime(), 10);
                        path.draw(g, x - 17 + row + 2 + 1, y + col + 1 + 3);
                    }
                    ++i;
                }
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(100);
                            LotteryNineBtn.isXIPAI = false;
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            } else {
                while (i < 9) {
                    final int row = i % 3 * 72;
                    final int col = i / 3 * 72;
                    if (LotteryFromServerUntil.Goodslist != null && LotteryFromServerUntil.Goodslist.size() >= 9) {
                        if (LotteryFromServerUntil.Goodslist.get(i).getLotterystep() == 1) {
                            g.drawImage(image, x - 17 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                        } else {
                            if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG01")) {
                                g.drawImage(bgimage1, x - 17 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                            } else if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG02")) {
                                g.drawImage(bgimage2, x - 17 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                            } else if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG03")) {
                                g.drawImage(bgimage3, x - 17 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                            } else if (LotteryFromServerUntil.Goodslist.get(i).getLotterybg().equals("FFBG04")) {
                                g.drawImage(bgimage4, x - 17 + row + 2 + 1, y + col + 1 + 3, 70, 70, null);
                                tcp.updateToTime(ImageMixDeal.userimg.getTime(), 4);
                                tcp.draw(g, x - 23 + row + 2 + 1, y + col + 1 - 1);
                            }

                            g.drawImage(CutButtonImage.getImage("img/item/" + LotteryFromServerUntil.Goodslist.get(i).getSkin() + ".png", -1, -1).getImage(), x -10 + row + 2 + 1, y + col + 1 + 10, 53, 53, null);
                        }
                    }
                    ++i;
                }
                LotteryNineBtn.isXIPAI = false;
            }
        }
    }

    public static void startLottery() {
        if (!hasStart) {
            Collections.shuffle(Goodslist);
            hasStart = true;
            for (LotteryGood lotteryGood : LotteryFromServerUntil.Goodslist) {
                lotteryGood.setLotterystep(1);
            }
        }
    }
    public static void drop(){
        hasStart = false;
        record = 0;
        setGoodslist(new ArrayList<LotteryGood>());
        setShowlist(new ArrayList<LotteryGood>());
    }

    public static List<LotteryGood> getGoodslist() {
        return Goodslist;
    }

    public static void setGoodslist(List<LotteryGood> goodslist) {
        Goodslist = goodslist;
    }

    public static void setGoods(ArrayList<LotteryGood> goodslist) {
        Goodslist = goodslist;
        for(LotteryGood lotteryGood :Goodslist){
            //lotteryGood.setLotteryIcon(GoodsListFromServerUntil.imgpath(lotteryGood.getSkin()));
        }
    }

//    public static ImageIcon[] getGoodimg() {
//        return goodimg;
//    }
//
//    public static void setGoodimg(ImageIcon[] goodimg) {
//        LotteryFromServerUntil.goodimg = goodimg;
//    }

    public static List<LotteryGood> getShowlist() {
        return showlist;
    }

    public static void setShowlist(List<LotteryGood> showlist) {
        LotteryFromServerUntil.showlist = showlist;
    }
}
